package produceconsumer2;

import java.util.LinkedList;

public class Producer {

    private LinkedList<String> list = new LinkedList<>();
    private Object lock;
    private Integer count = 0;

    public Producer(LinkedList<String> list, Object lock) {
        this.list = list;
        this.lock = lock;
    }

    public void createProduct() throws InterruptedException {
        while(true){
           synchronized (lock){
               if(list.isEmpty()){
                   count++;
                   String str = "product "+count;
                   list.add(str);
                   System.out.println(str+" is creating!!!");
               }else {
                   lock.wait();
               }
               Thread.sleep(100);
           }
        }
    }
}
